package Q2;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        long[] dp = new long[n + 1];
        for (int i = 1; i < n + 1; i++) {
            dp[i] = Math.max(dp[i - 1] + arr[i - 1], arr[i - 1]);
        }

        long ret = Integer.MIN_VALUE;
        for (int i = 1; i < n + 1; i++) {
            ret = Math.max(ret, dp[i]);
        }

        System.out.println(ret);
    }
}